import heapq
from collections import OrderedDict, defaultdict, deque, Counter

#1列表 动态数组
nums =[1,2,3,4]
strs =list("hello")

nums.append(5)
nums.insert(1,6)
nums.pop(2)
nums.sort(reverse=True)
sub_nums = nums[1:3]

#2 元组 不可变有序结构
point =(3,4)
single=(5,)
info = tuple(["Alice",25])

x,y=point
print(point[0])
print("Alice" in info)

#3 集合 无须去重结构
s1={1,2,3,3}
s2 = set([3,4,5])
s1.add(4)
s1.remove(2)
s1.discard(6)
union =s1|s2
intersection = s1&s2
difference = s1-s2

#4 字典 键值对影射
user ={"name":"alice","age":25,"city":"beijing"}
empty_dict=dict()
from_list = dict([("a",1),("b",2)])
user["gender"]="female"
print(user.get("age"))
print(user.pop("city"))
for k,v in user.items():
    print(f"{k}:{v}")

#5 有序字典 保持插入顺序
od = OrderedDict([("a",1),("b",2),("c",3)])
od.move_to_end("a")
od.popitem(last=False)

#6 默认字典 自动初始化
group = defaultdict(list)
group["math"].append(90)
group["math"].append(85)
count = defaultdict(int)
count["apple"]+=1

#7 双端队列 高效两端操作
dq =deque([1,2,3])
dq.append(4)
dq.appendleft(0)
dq.pop()
dq.popleft()
dq.rotate(1)

#8 计数器 快速统计元素频次
words =["apple","banana","apple","orange","apple"]
words_count = Counter(words)
strs_count =Counter("abracadabra")
print(words_count["apple"])
print(words_count.most_common(2))
words_count.update(["banana","grape"])

#9 堆 优先队列
min_heap = []
heapq.heappush(min_heap,3)
heapq.heappush(min_heap,1)
